import 'package:sainbainu/common/apis/login_api.dart';
import 'package:sainbainu/common/models/request/apple_auth_request.dart';
import 'package:sainbainu/common/models/request/jverify_login_request.dart';
import 'package:sainbainu/common/models/request/password_login_request.dart';
import 'package:sainbainu/common/models/request/sms_login_request.dart';

class LoginRepository {
  final LoginApi _loginApi;

  LoginRepository(this._loginApi);

  /// 临时登录
  Future<String> tempLogin(int customerId) async {
    var res = await _loginApi.tempLogin({"customerId": customerId});
    return res['msg']; // msg 就是 token
  }

  /// 一键登录
  Future<Map<String, dynamic>> jpushLogin(
    JverifyLoginRequest jverifyLoginRequest,
  ) async {
    var res = await _loginApi.jpushLogin(jverifyLoginRequest.toJson());
    return res['data'];
  }

  /// 短信验证码登录
  Future<Map<String, dynamic>> smsCodeLogin(
    SmsLoginRequest smsLoginRequest,
  ) async {
    var res = await _loginApi.smsCodeLogin(smsLoginRequest.toJson());
    return res['data'];
  }

  /// 密码登录
  Future<Map<String, dynamic>> passwordLogin(
    PasswordLoginRequest passwordLoginRequest,
  ) async {
    var res = await _loginApi.passwordLogin(passwordLoginRequest.toJson());
    return res['data'];
  }

  /// 微信登录
  Future<Map<String, dynamic>> wechatLogin({
    required String code,
    String? registrationId,
  }) async {
    var res = await _loginApi.wechatLogin({
      'code': code,
      'registrationId': registrationId,
    });
    return res['data'];
  }

  /// apple 登录
  Future<Map<String, dynamic>> appleLogin({
    required AppleAuthRequest appleAuthRequest,
    String? registrationId,
  }) async {
    var params = appleAuthRequest.toJson();
    params['registrationId'] = registrationId;
    var res = await _loginApi.appleLogin(params);
    return res['data'];
  }
}
